from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
"""
django虽然没有给你提供定义char字段的方法 但是给你暴露一个接口 
用户可以自定义char字段
"""
class MyChar(models.Field):
    def __init__(self, max_length, *args, **kwargs):
        self.max_length = max_length
        super().__init__(max_length=max_length, *args, **kwargs)

    def db_type(self, connection):
        return 'char(%s)' % self.max_length

from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class UserInfo(AbstractUser):
    phone = models.BigIntegerField(null=True,blank=True)  # blank是用来告诉admin后台 该字段可以不填
    # avatar存的是用户头像文件路径 用户上传的头像会自动保存到avatar文件夹下
    avatar = models.FileField(upload_to='avatar/',default='avatar/default.jpg')
    create_time = models.DateField(auto_now_add=True)

    # blog = models.OneToOneField(to='Blog',null=True)

    class Meta:
        verbose_name_plural = '用户表'
        # verbose_name =  '用户表'

    def __str__(self):
        return self.username
# 赊账记录
# 人名，地址，电话，金额，时间,备注
class ToMoney(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)    #
    path = models.CharField(max_length=255)  # 地址
    telephone = models.CharField(max_length=255)
    money = models.IntegerField(null=True)
    ps = models.CharField(max_length=255)  # 备注
    is_delete = models.IntegerField(default=0)
    register_time = models.DateField()

    def __str__(self):
        return self.name


# 还款记录表
class AddMoney(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)  #
    path = models.CharField(max_length=255)  # 地址
    telephone = models.CharField(max_length=255)
    add_money = models.IntegerField(null=True)
    sum_money = models.IntegerField(null=True)
    ps = models.CharField(max_length=255)  # 备注
    is_delete = models.IntegerField(default=0)
    register_time = models.DateField()

    def __str__(self):
        return self.name





# 销账名单
class SeMoney(models.Model):
    table_name = 'se_money'
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)  #
    path = models.CharField(max_length=255)  # 地址
    telephone = models.CharField(max_length=255)
    add_money = models.IntegerField(null=True)
    sum_money = models.IntegerField(null=True)
    ps = models.CharField(max_length=255) # 备注
    is_delete = models.IntegerField(default=0)
    register_time = models.DateField()

    def __str__(self):
        return self.name